package org.lanqiao.ssm.common.core.service;

import java.io.Serializable;
import java.util.List;

import org.lanqiao.ssm.common.core.dao.BaseDAO;
import org.lanqiao.ssm.common.exceptions.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 
 * @author liuwei
 * 
 * @param <E>
 * @param <QM>
 */

public abstract class BaseService<E, ID extends Serializable> implements BaseServiceI<E, ID> {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	public abstract BaseDAO<E, ID> getDao();

	public int deleteByPrimaryKey(ID id) {
		if (StringUtils.isEmpty(id))
			throw BizException.DB_ERROR_PARAM_0;
		return getDao().deleteByPrimaryKey(id);
	}

	public int insert(E record) {
		return getDao().insert(record);
	}

	public int insertSelective(E record) {
		return getDao().insertSelective(record);
	}

	public E selectByPrimaryKey(ID id) {
		if (StringUtils.isEmpty(id))
			throw BizException.DB_ERROR_PARAM_0;
		return (E) getDao().selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(E record) {
		return getDao().updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(E record) {
		return getDao().updateByPrimaryKey(record);
	}

	public PageInfo<E> findObjectsByPage(E m, int page, int pageShow) {
		PageHelper.startPage(page, pageShow);
		List<E> list = getDao().findObjectsByPage(m);
		return new PageInfo<E>(list);
	}
}
